package com.yxy.controller.admin;

import com.yxy.common.PageResult;
import com.yxy.common.Result;
import com.yxy.constant.RequestMapperConstant;
import com.yxy.pojo.dto.RouteDTO;
import com.yxy.pojo.dto.RoutePageQueryDTO;
import com.yxy.pojo.entity.Geography;
import com.yxy.service.RouteService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminRouteController")
@RequestMapping(RequestMapperConstant.ADMIN_REQUEST_MAPPER + "route")
@Slf4j
public class RouteController {

    @Autowired
    private RouteService routeService;

    /**
     * 获取所有地理信息
     * @return
     */
    @GetMapping("/getGeography")
    public Result<List<Geography>> getGeography() {
        log.info("获取所有地理信息");
        List<Geography> voList = routeService.getGeography();
        return Result.success("", voList);
    }

    /**
     * 分页查询路线信息
     * @param routePageQueryDTO
     * @return
     */
    @GetMapping("/pageQuery")
    public Result<PageResult> pageQuery(RoutePageQueryDTO routePageQueryDTO){
        log.info("分页查询路线信息：{}", routePageQueryDTO);
        PageResult pageResult = routeService.pageQuery(routePageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 添加路线信息
     * @param routeDTO
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody RouteDTO routeDTO){
        log.info("添加路线信息：{}", routeDTO);
        routeService.add(routeDTO);
        return Result.success("添加成功");
    }

    /**
     * 批量删除路线
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除路线：{}", ids);
        routeService.batchDelete(ids);
        return Result.success("删除成功");
    }

    /**
     * 修改路线信息
     * @param routeDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody RouteDTO routeDTO){
        log.info("修改路线信息：{}", routeDTO);
        routeService.update(routeDTO);
        return Result.success("修改成功");
    }
}
